package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.StfArchives;
import com.ruoyi.bussiness.service.IStfArchivesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全档案Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/archives")
public class StfArchivesController extends BaseController
{
    private String prefix = "bussiness/archives";

    @Autowired
    private IStfArchivesService stfArchivesService;

    @RequiresPermissions("bussiness:archives:view")
    @GetMapping()
    public String archives()
    {
        return prefix + "/archives";
    }

    /**
     * 查询安全档案列表
     */
    @RequiresPermissions("bussiness:archives:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StfArchives stfArchives)
    {
        startPage();
        List<StfArchives> list = stfArchivesService.selectStfArchivesList(stfArchives);
        return getDataTable(list);
    }

    /**
     * 导出安全档案列表
     */
    @RequiresPermissions("bussiness:archives:export")
    @Log(title = "安全档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StfArchives stfArchives)
    {
        List<StfArchives> list = stfArchivesService.selectStfArchivesList(stfArchives);
        ExcelUtil<StfArchives> util = new ExcelUtil<StfArchives>(StfArchives.class);
        return util.exportExcel(list, "安全档案数据");
    }

    /**
     * 新增安全档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存安全档案
     */
    @RequiresPermissions("bussiness:archives:add")
    @Log(title = "安全档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StfArchives stfArchives)
    {
        return toAjax(stfArchivesService.insertStfArchives(stfArchives));
    }

    /**
     * 修改安全档案
     */
    @RequiresPermissions("bussiness:archives:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StfArchives stfArchives = stfArchivesService.selectStfArchivesById(id);
        mmap.put("stfArchives", stfArchives);
        return prefix + "/edit";
    }

    /**
     * 修改保存安全档案
     */
    @RequiresPermissions("bussiness:archives:edit")
    @Log(title = "安全档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StfArchives stfArchives)
    {
        return toAjax(stfArchivesService.updateStfArchives(stfArchives));
    }

    /**
     * 删除安全档案
     */
    @RequiresPermissions("bussiness:archives:remove")
    @Log(title = "安全档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stfArchivesService.deleteStfArchivesByIds(ids));
    }
}
